//
//  shameViewController.m
//  YiXiu
//
//  Created by ZHY on 16/6/26.
//  Copyright © 2016年 zzz. All rights reserved.
//

#import "shameViewController.h"
#import "AppDelegate.h"
#import "BaseTabBarController.h"
#import "AlwayScrollerView.h"
#import "shameTableViewCell.h"
#import "shamModel.h"
#import "ShameDetalVC.h"

@interface shameViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView * tableView;
@property(nonatomic,assign)int index;

@property(nonatomic,strong)NSMutableArray * dataArr;
@property(nonatomic,strong)NSMutableArray * imgArr;




@end

@implementation shameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.view.backgroundColor = [UIColor redColor];
    self.view.backgroundColor = [UIColor whiteColor];
    self.dataArr = [NSMutableArray array];
    self.imgArr = [NSMutableArray array];

    self.title = @"羞色";
    
//   http://115.29.174.31:8080/users/addAndLogin?u_name=zz&u_sex=zz&u_label=zz&u_headUrl=zz&u_username=zz;
    
    [self.view addSubview:self.tableView];
 
    [self getLoad];
    
}



-(UITableView *)tableView{
    
    
    if (!_tableView) {
        CGRect rect = self.view.frame;
        rect.origin.y = 0;
        
        _tableView = [[UITableView alloc]initWithFrame:rect style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
        
    }
    
    return _tableView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.dataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    shameTableViewCell * cell = [[shameTableViewCell alloc]initWithTableView:tableView];
    cell.model = [self.dataArr objectAtIndex:indexPath.row];
    
    
    return cell;
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    
    return 92;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    
    return 191 +20;
}



-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIView *firstSubView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 191)];
//    firstSubView.backgroundColor = [UIColor redColor];
    firstSubView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:firstSubView];
    
    NSArray * arr = self.imgArr;
    AlwayScrollerView *scroller = [AlwayScrollerView alwayScrollerViewWithImgURLArr:arr frame:CGRectMake(0, 0, kScreenWidth, 191)];
    [scroller autoAnimetionTimeInterval:3];
    [scroller setIsHidenPageController:NO];
    [firstSubView addSubview:scroller];
    
    return firstSubView;
}





- (void)getLoad{
    
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    /*
     Dang	String	第几页
     */
    dic[@"dang"] = [NSString stringWithFormat:@"%d",1];
    dic[@"p_type"] = [NSString stringWithFormat:@"%d",2];

    
    [NetWorkingTool POST:@"selfPost/xiuSe" parameters:dic success:^(id responseObject, NSError *error) {
        NSLog(@"----selfPost/index---%@--%@",responseObject,error);
        [self.dataArr removeAllObjects];
        [self.imgArr removeAllObjects];
        
        NSArray * imgs = [responseObject objectForKey:@"json1"];
        for (NSDictionary * dic in imgs) {
            NSString * imageurl = [dic valueForKey:@"gd_url"];
            [self.imgArr addObject:imageurl];
        }
        
        
        NSArray * dics = [responseObject objectForKey:@"json2"];
        for (NSDictionary * dic in dics) {
            shamModel * model = [shamModel mj_objectWithKeyValues:dic];
            [self.dataArr addObject:model];
            
        }
        
        [self.tableView reloadData];
        
    } failure:^(id responseObject, NSError *error) {
        NSLog(@"----selfPost/index--%@--%@",responseObject,error);
        
        [MBProgressHUD showError:[error description]];
    }];
    
//    [NetWorkingTool GET:@"http://115.29.174.31:8080/xiuseAPP/selfPost/xiuSe?dang=1&p_type=2" success:^(id responseObject, NSError *error) {
//        NSLog(@"----selfPost/index---%@--%@",responseObject,error);
//        [self.dataArr removeAllObjects];
//        [self.imgArr removeAllObjects];
//        
//        NSArray * imgs = [responseObject objectForKey:@"json1"];
//        for (NSDictionary * dic in imgs) {
//            NSString * imageurl = [dic valueForKey:@"gd_url"];
//            [self.imgArr addObject:imageurl];
//        }
//        
//        
//        NSArray * dics = [responseObject objectForKey:@"json2"];
//        for (NSDictionary * dic in dics) {
//            shamModel * model = [shamModel mj_objectWithKeyValues:dic];
//            [self.dataArr addObject:model];
//            
//        }
//        
//        [self.tableView reloadData];
//
//    } failure:^(id responseObject, NSError *error) {
//        
//        NSLog(@"----selfPost/index--%@--%@",responseObject,error);
//        
//        [MBProgressHUD showError:[error description]];
//
//    }];
    
    
}
// http://115.29.174.31:8080/xiuseAPP/selfPost/xiuSe?dang=1&p_type=2
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ShameDetalVC * shameDetal = [[ShameDetalVC alloc]init];
    
    shamModel * model = [self.dataArr objectAtIndex:indexPath.row];
    shameDetal.p_id = model.p_id;
    
    [self.navigationController pushViewController:shameDetal animated:YES];
}




// http:/115.29.174.31:8080/xiuseAPP/selfPost/xiuSe?Dang=1



@end
